package youkeda;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Socket;

public class FileUploadClient {
    public static void main(String[] args) throws IOException {
        //读取要上传的文件
        FileInputStream fileInputStream=new FileInputStream("C:\\Users\\鱼尾\\Desktop\\微信图片_20220320212742.jpg");
        Socket socket=new Socket("127.0.0.1",8888);
        System.out.println("文件上传");
        byte[] bytes=new byte[1024];
        int len = 0;
        //写入自己将要上传的信息内容
        while ((len=fileInputStream.read(bytes))!=-1){
            socket.getOutputStream().write(bytes,0,len);
        }

        //告诉服务器已经传输结束
        socket.shutdownOutput();

        //接收服务端传过来的信息
       while ((len=socket.getInputStream().read(bytes))!=-1){
           System.out.println(new String(bytes,0,len));
       }

       //释放资源
        fileInputStream.close();
        socket.close();

    }
}
